/**********************************************************************
 Name:  TestCalculateVisitRange,测试用例
 Purpose: 在PDA上传新的店面拜访记录时，计算当期坐标与对应的店面标准坐标的距离                                                           
-------                                                             
======================================================
History                                                            
-------                                                            
VERSION  AUTHOR               DATE                 DETAIL                                
   1.0 -      huang xiaojiang      03/21/2010      Create          : 
***********************************************************************/
@isTest
private class TestCalculateVisitRange{
   
    static testMethod void test(){
    
           Profile p=[select  id from profile where  name='Sales Rep - Trade' limit 1];
           User u=new user(alias='hxj',email='xjhuang80ww7@isoftstone.com',lastName='testing'
               ,languageLocaleKey='zh_CN',localeSidkey='zh_CN' ,TimeZoneSidKey='Asia/Shanghai',EmailEncodingKey='UTF-8',
               profileId=p.id,userName='xjhuang123@isoftstone.com');
               
               System.runAs(u){
                      
                       //新建地区
                      Place__c oPlace=new Place__c();
                      oPlace.name='地区1';
                      oPlace.CityType__c='Base City';
                      oPlace.PlaceType__c='City';
                      oPlace.CityCode__c='c001';
                      insert oPlace;
                      
                      //新建店面
                      Account oAcc=new   Account();
                      oAcc.Name='店面1';
                      oAcc.City__c=oPlace.id;
                      oAcc.Channel__c='百货店';
                      oAcc.Contact__c='aaa';
                      oAcc.No_of_checkout__c=22;
                      oAcc.ContactPhoneNumber__c='1234567456';
                      oAcc.lat__c='23.008760201342253';
                      oAcc.lon__c='113.5917953491211';
                      insert oAcc;
                      
                      Account oAcc1=new   Account();
                      oAcc1.Name='店面2';
                      oAcc1.City__c=oPlace.id;
                      oAcc1.Channel__c='百货店2';
                      oAcc1.Contact__c='aaa1222';
                      oAcc1.No_of_checkout__c=2211;
                      oAcc1.ContactPhoneNumber__c='12345617456';
                      oAcc1.lat__c='26.008760201342253';
                      oAcc1.lon__c='104.5917953491211';
                      insert oAcc1;
                      
                       //拜访计划       
                       //今天
                      Routing_Plan_And_Visit__c oRPAV=new  Routing_Plan_And_Visit__c();
                      oRPAV.Visit_Date__c=date.today();
                      insert oRPAV;
                      
                      //计划
                      RoutingPlan__c oRP=new RoutingPlan__c();
                      oRP.RoutingPlanAndVisit__c=oRPAV.Id;
                      oRP.OutletName__c=oAcc.Id;
                      oRP.StartDateTime__c=dateTime.now();
                      oRP.EndDateTime__c=dateTime.now().addHours(4);
                      insert oRP;
                      
                       //新建instoreVisit记录
                        list<In_Store_Visit__c> lstISV=new  list<In_Store_Visit__c>();
                        In_Store_Visit__c oISV1=new  In_Store_Visit__c();
                        oISV1.RoutingPlanAndVisit__c=oRPAV.id;
                        oISV1.Start_Time__c=dateTime.now();
                        oISV1.End_Time__c=dateTime.now().addHours(1);
                        oISV1.OutletName_del__c=oAcc.id;
                        oISV1.lat__c='26.608760201342253';
                        oISV1.lon__c='193.5917953491211';
                        lstISV.add(oISV1);

                         In_Store_Visit__c oISV2=new  In_Store_Visit__c();
                        oISV2.RoutingPlanAndVisit__c=oRPAV.id;
                        oISV2.Start_Time__c=dateTime.now().addHours(1);
                        oISV2.End_Time__c=dateTime.now().addHours(2);
                        oISV2.OutletName_del__c=oAcc1.id;
                        oISV2.lat__c='26.008760201342253';
                        oISV2.lon__c='104.5917953491211';
                        lstISV.add(oISV2);
                        
                        insert lstISV;

               }
        
    }
}